package com.gtw.modules.api.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.gtw.common.annotation.AuthIgnoreSys;
import com.gtw.common.utils.Query;
import com.gtw.common.utils.R;
import com.gtw.common.validator.ValidatorUtils;
import com.gtw.common.validator.group.AddGroup;
import com.gtw.modules.api.service.TbRaidDetailsService;
import com.gtw.modules.entity.TbRaidDetails;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/** API 佣金明细
 *
 * @author wuye
 * @date 2018/1/25
 */
@RestController
@RequestMapping("/api/raid")
public class ApiTbRaidDetailsController {

    @Autowired
    private TbRaidDetailsService tbRaidDetailsService;


    /**
     * 根据条件获取佣金明细列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("api:raid:list")
    public R list(@RequestParam Map<String, Object> params){
        //查询列表数据
        Query query = new Query(params);
        Page<TbRaidDetails> pageUtil = new Page<TbRaidDetails>(query.getPage(), query.getLimit());
        Page<TbRaidDetails> page = tbRaidDetailsService.queryPageList(pageUtil,query);
        return R.ok().put("page", page);
    }


    /**
     * 添加一条佣金明细
     * @param tbRaidDetails
     * @return
     */
    @RequestMapping("/save")
    @RequiresPermissions("api:raid:save")
    public R save(@RequestBody TbRaidDetails tbRaidDetails){
        ValidatorUtils.validateEntity(tbRaidDetails, AddGroup.class);
        tbRaidDetailsService.save(tbRaidDetails);
        return R.ok();
    }
}
